package middlewares

import (
	"HeadLineNews/pkg/zaplog"
	"HeadLineNews/resp"
	"github.com/gin-gonic/gin"
)

// GinRecovery 全部拦截 panic
func GinRecovery(c *gin.Context) {
	defer func() {
		if r := recover(); r != nil {
			zaplog.L().Error("system panic", zaplog.Fields(c, nil, r)...)
			resp.ServerPanic(c)
			c.Abort()
			return
		}
	}()
	c.Next()
}
